const date = {
    formatTime (value = '') 
    {
        // 通过时间戳转字符串或者获取时间字符串
        let date = value ? new Date(value) : new Date();
        let yy = date.getFullYear();
        let mm = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
        let dd = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
        let hh = date.getHours() < 10 ? '0' +  date.getHours() : date.getHours();
        let mf = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
        let ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
        return yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
    },
    // 转时间戳 2022-12-12
    formatTimeStamp (time)
    {    
        if (!time)
        {
            return 0;
        }
        let date = time.replace(/-/g, '/');
        let timestamp = new Date(date).getTime();
        return timestamp;
    },
    // 获取当前时分
    getHoursMinutes (time)
    {
        let date = time;
        let hh = date.getHours() < 10 ? '0' +  date.getHours() : date.getHours();
        let mf = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
        return hh + ':' + mf; 
    }
}

module.exports = date;